﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;

namespace NhaSachDAO
{
    public class KhachHang
    {
        public static DataTable LoadKhachHang()
        {
            SqlConnection cnn = SQLconnection.Hamketnoi();
            SqlCommand cnd = new SqlCommand("select * from KhachHang", cnn);
            cnd.CommandType = CommandType.Text;
            SqlDataAdapter da = new SqlDataAdapter(cnd);
            DataTable dt = new DataTable();
            da.Fill(dt);
            return dt;
        }
        public static void XoaKhachHang(int makh)
        {
            SqlConnection cnn = SQLconnection.Hamketnoi();
            SqlCommand cmd = new SqlCommand("DELETE FROM KhachHang WHERE (MaKH = " + makh + ")", cnn);
            cmd.CommandType = CommandType.Text;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
        public static void ThemKhachHang( string hotenkh,string gioitinh,string diachi,string email,string sdt,string sotaikhoan,int sodiem)
        {
            SqlConnection cnn = SQLconnection.Hamketnoi();
            SqlCommand cmd = new SqlCommand("Insert into KhachHang(HoTenKH,GioiTinh,DiaChi,Email,SoDT,SoTaiKhoan,SoDiem) Values ( N'" + hotenkh + "',N'"+gioitinh+"',N'"+diachi+"',N'"+email+"',N'"+sdt+"',"+sotaikhoan+","+sodiem+")", cnn);
            cmd.CommandType = CommandType.Text;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
        public static void CapNhatKhachHang(int makh,string hotenkh, string gioitinh, string diachi, string email, string sdt, string sotaikhoan, int sodiem)
        {
            SqlConnection cnn = SQLconnection.Hamketnoi();
            SqlCommand cmd = new SqlCommand("Update KhachHang set HoTenKH=N'" + hotenkh + "',GioiTinh=N'" + gioitinh + "',DiaChi=N'" + diachi + "',Email=N'" + email + "',SoDT=N'"+sdt+"',SoTaiKhoan=" + sotaikhoan + ",SoDiem=" + sodiem + " Where (MaKH="+makh+")", cnn);
            cmd.CommandType = CommandType.Text;
            cnn.Open();
            cmd.ExecuteNonQuery();
            cnn.Close();
        }
    }
}
